package com.itany.book.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itany.exception.ManagerUserException;
import com.itany.mapper.ManagerUserMapper;
import com.itany.pojo.ManagerUser;
import com.itany.service.ManagerUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.rmi.ServerException;
import java.util.List;

/**
 * Author:梁辰
 * 时间:19-4-3 上午10:06
 * description:
 * version:1.0
 */
@Service
@Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
public class ManagerUserServiceImpl implements ManagerUserService {
    @Autowired
    ManagerUserMapper managerUserMapper;

         @Transactional(readOnly=true)
        public PageInfo<ManagerUser> findUserAll (Integer page, Integer rows){
            PageHelper.startPage(page, rows);
            List<ManagerUser> list = managerUserMapper.findUserAll();
            PageInfo<ManagerUser> info = new PageInfo<ManagerUser>(list);
            return info;
        }


    @Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
    public ManagerUser login(ManagerUser user) throws ManagerUserException, ServerException {
        System.out.println("111111111111111");
        ManagerUser  managerUser = managerUserMapper.selectByUsernameAndPassword(user);
        System.out.println("2222222222222");
        if(null == managerUser){
            throw new ManagerUserException("用户名/密码错误");
        }
        return managerUser;
    }
}
